/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DA;

import BE.DiaSemana;
import BE.Frecuencia;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;

/**
 *
 * @author andre
 */
public class FrecuenciaDA {
    public static HashMap< Integer, List<Integer> >  recuperaFrecuencias () {
        
        Session hbsession = HUtil.getSessionFactory().openSession();
        try{
            Query query = hbsession.createQuery("FROM Frecuencia");

            
            hbsession.close();
            
            List<Frecuencia> temp = query.list();
        
            
            HashMap< Integer, List<Integer> > res = new HashMap< Integer, List<Integer > >();
            for( Frecuencia frec : temp){
                
                List<Integer> dias = new ArrayList<Integer>();
                for( Object obj : frec.getDiaSemanas()){
                    DiaSemana dia = ( DiaSemana ) obj;
                    dias.add(dia.getIdDiaSemana());
                }
                res.put( frec.getIdFrecuencia() , dias );
            
            }
            return res;
            
        }catch(Exception ex){
              hbsession.close();
              return null;
        }
    }
    
    
    
}
